﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Script.Serialization;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace DATN
{
    public partial class Test : System.Web.UI.Page
    {
        string cnnString;
        SqlConnection cnn;
        SqlCommand cmd;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                String data = Request.Form[0];
                Response.Write(data);
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                //serializer.DeserializeObject
                //Label1.Text = data;
                Insert(data);
            }catch(Exception ex)
            {
                Response.Write("Blah blah");
            }
        }

        //Bat Create 
        public void Insert(string data)
        {
            try
            {
                cnnString = ConfigurationManager.ConnectionStrings["DATNconnection"].ToString();
                cnn = new SqlConnection(cnnString);
                cnn.Open();

                cmd = cnn.CreateCommand();
                cmd.CommandText = "INSERT INTO [dbo].[Notes] ([Name], [Us_Id])"
                                + "VALUES (@Name, @Us_Id)";

                cmd.Parameters.Add("@Us_Id", SqlDbType.Int);
                cmd.Parameters["@Us_Id"].Value = 4;

                cmd.Parameters.Add("@Name", SqlDbType.NVarChar);
                cmd.Parameters["@Name"].Value = data;
                cmd.ExecuteNonQuery();

                cnn.Close();
            }
            catch (Exception ex)
            {
                Response.Write(ex);
            }   
        }
    }
}